//
//  BGStatusToolBarView.swift
//  WeiboSwift
//
//  Created by 战场原黑仪 on 16/7/25.
//  Copyright © 2016年 战场原黑仪. All rights reserved.
//

import UIKit

class BGStatusToolBarView: UIView {
    
    var cellModel: BGHomeCellModel?{
        didSet{
            retweetButton.setTitle(cellModel?.repostsCountStr, forState: .Normal)
            commentButton.setTitle(cellModel?.commentsCountStr, forState: .Normal)
            unlikeButton.setTitle(cellModel?.attitudesCountStr, forState: .Normal)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setupUI()
        self.setupLayout()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 设置视图
    private func setupUI() {
//        backgroundColor = RandomColor()
        
        self.addSubview(retweetButton)
        self.addSubview(commentButton)
        self.addSubview(unlikeButton)
        self.addSubview(line1)
        self.addSubview(line2)
    }
    
    private func setupLayout() {
        retweetButton.snp_makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
                commentButton.snp_makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp_trailing)
            make.width.equalTo(unlikeButton)
        }
        unlikeButton.snp_makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        line1.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        line2.snp_makeConstraints { (make) in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
    }
    
    //MARK: - 懒加载
    //转发
    private lazy var retweetButton: UIButton = {
        let btn: UIButton = self.addChildButton("timeline_icon_retweet", title: "转发")
        return btn
    }()
    //评论
    private lazy var commentButton: UIButton = {
        let btn: UIButton = self.addChildButton("timeline_icon_comment", title: "评论")
        return btn
    }()
    //点赞
    private lazy var unlikeButton: UIButton = {
        let btn: UIButton = self.addChildButton("timeline_icon_unlike", title: "赞")
//            btn.setImage(<#T##image: UIImage?##UIImage?#>, forState: <#T##UIControlState#>)
        return btn
    }()
    
    //分割线
    private lazy var line1: UIImageView = {
        let line = self.addSplitLine()
        return line
    }()
    private lazy var line2: UIImageView = {
        let line = self.addSplitLine()
        return line
    }()
}

//MARK: - 小方法
extension BGStatusToolBarView {
    
    //添加分割线
    private func addSplitLine() -> UIImageView{
        let line = UIImageView(imageName: "timeline_card_bottom_line")
        return line
    }
    
    private func addChildButton(imageName: String, title: String) -> UIButton {
        
        let btn = UIButton();
            btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
            btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
            btn.setImage(UIImage(named: imageName), forState: .Normal)
        
            btn.titleLabel?.font = UIFont.systemFontOfSize(15)
            btn.setTitleColor(DarkGrayColor, forState: .Normal)
            btn.setTitle(title, forState: .Normal)
        return btn
    }
    
}
